﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SnmpForm.DbWrapper.DbDataTypes;

namespace SnmpForm.ApSearch
{
    public partial class ucSearchTarget : UserControl
    {
        public ucSearchTarget()
        {
            InitializeComponent();
        }
        public void Update(bool bView=true)
        {
            if (bView)
            {
                if (_Value != null)
                {
                    byte[] bytesFrom =
                        IPAddressExtend.IpByteByStr(_Value.from);
                    ipAddressControlFrom.SetAddressBytes(bytesFrom);

                    byte[] bytesTo =
                        IPAddressExtend.IpByteByStr(_Value.to);
                    ipAddressControlTo.SetAddressBytes(bytesTo);
                }
            }
            else
            {
                byte[] bytesFrom = 
                    ipAddressControlFrom.GetAddressBytes();
                _Value.from = 
                    IPAddressExtend.IpStrByByte(bytesFrom);

                byte[] bytesTo =
                    ipAddressControlTo.GetAddressBytes();
                _Value.to =
                    IPAddressExtend.IpStrByByte(bytesTo);
            }
        }
        private SearchTarget _Value = new SearchTarget();
        public SearchTarget Value
        { 
            get {
                Update(false);
                return this._Value; 
            } 
            set {
                Update();
                this._Value = value; 
            } 
        } 
    }
}
